package com.df.bpm.utils.businessViewerV2.business;

import com.df.bpm.utils.businessViewerV2.Main;
import com.df.bpm.utils.businessViewerV2.res.V_scrollPanel;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class V_scroll4SuperiorBusinessDto extends V_scrollPanel<M_businessLocationsDTO4Subset> {

    V_businessByOutput baba;

    public V_scroll4SuperiorBusinessDto( V_businessByOutput baba){
        this.baba=baba;
        this.putModel(null);
    }

    @Override
    public List<String> getColNames() {
        return Arrays.asList("业务ID", "序号","父级业务","创建时间","更新时间");
    }

    @Override
    public void hideCol(JTable iTable) {
        Main.hideCol(iTable,0);
    }

    @Override
    public List<Integer> colWidthSetting() {
        return new ArrayList<>(Arrays.asList(1,3,11,11,11));
    }

    @Override
    public Object[] getRowValues(M_businessLocationsDTO4Subset row) {
        return new Object[]{row.getSuperior(),-1,row.getSuperiorDesc(),
                dateFormat.format(row.getCreateDate()),
                dateFormat.format(row.getUpdateDate())};
    }

    @Override
    public M_businessLocationsDTO4Subset getEmptyRow() {
        return new M_businessLocationsDTO4Subset();
    }

    @Override
    public MouseListener mouseAdapter4Table(JTable iTable, List<M_businessLocationsDTO4Subset> list) {
        return new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int row = iTable.rowAtPoint(e.getPoint());
                int col = iTable.columnAtPoint(e.getPoint());
                if (row >= 0 ) {
                    if (e.getClickCount() == 2) {// 处理双击事件
                        if(col==1){// 查询业务详情
                            M_businessLocationsDTO4Subset temp = list.get(row);
                            baba.setActiveBusiness(temp.getSuperior(),temp.getSuperiorDesc());
                            baba.vHistory.insert(list.get(row).getSuperior(),list.get(row).getSuperiorDesc());
                        }
                    }
                }
            }
        };
    }

}
